﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace Nexterday.Linq.Autocompiler
{
    public static class ExpressionExtensions
    {
        public static bool IsCapturedField(this MemberExpression expression)
        {
            return expression.Member.DeclaringType.Name.StartsWith("<>c__") && expression.Member.MemberType == System.Reflection.MemberTypes.Field;
        }

        public static int GetComplexity(this Expression expression)
        {
            var visitor=new ComplexityCalculatingExpressionVisitor();
            visitor.Visit(expression);
            return visitor.Complexity;
        }

    }
}
